<template>
  <div>
    <div class="goods-container">
    <div class="goods-card" v-for="item in goodsList" :key="item.id"
      @click="viewDetail(item.id)">
      <div class="goods-img">
        <el-image :src="item.mainImage" fit="cover"></el-image>
      </div>
      <div class="goods-name">{{ item.goodsName }}</div>
      <div class="goods-originalPrice">￥{{ item.originalPrice }}</div>
      <div class="goods-price">￥{{ item.price }}</div>
    </div>
    </div>
    <el-empty v-if="goodsList.length === 0"
      description="暂无数据"></el-empty> 
  </div>
</template>

<script>
  export default {
    name: 'GoodsList',
    props: {
      goodsList: {
        type: Array,
        default: []
      }
    },
    data(){
      return {
      }
    },
    methods: {
      viewDetail(id) {
        this.$router.push(`/index/goodDetail/${id}`);
      }
    }
  }
</script>

<style scoped lang="scss">
.goods-container {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr) );
  overflow: visible;
  .goods-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 5%;
    border-radius: 10px;
    box-sizing: border-box;
    transition: all 0.3s;
    text-align: left;
    .goods-img {
      width: 100%;
      padding-top: 90%;
      background-color: rgb(230, 229, 229);
      border-radius: 10px;
      position: relative;
      .el-image {
        border-radius: 10px;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
    }
    .goods-name {
      margin-top: 10px;
      font-size: 1.1em;
      width: 100%;
      font-weight: bold;
    }
    .goods-originalPrice {
      width: 100%;
      color: #00caa8;
      font-size: 0.85em;
      text-align: left;
      margin: 4px 0;
      text-decoration: line-through;
      opacity: 0.8;
    }
    .goods-price {
      width: 100%;
      color: #FF4F24;
      font-weight: bold;
      font-size: 1.2em;
    }
  }

  .goods-card:hover {
    cursor: pointer;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  }
}

@media screen and (max-width: 768px) {
  .goods-container {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr) );
  }
}
</style>
